<p>This rule raises an issue when legacy array flattening techniques are used instead of the native <code>Array#flat()</code> method introduced in
ES2019.</p>
<h2>Why is this an issue?</h2>
<p>ES2019 introduced the <code>Array#flat()</code> method as the standard way to flatten arrays. This method is more readable and expressive than
legacy techniques.</p>
<p>Before <code>Array#flat()</code>, developers used various workarounds to flatten arrays:</p>
<ul>
  <li> Using <code>flatMap()</code> with an identity function </li>
  <li> Using <code>reduce()</code> with <code>concat()</code> or spread operators </li>
  <li> Using <code>concat()</code> with <code>apply()</code> or spread syntax </li>
  <li> Using utility library functions like <code>_.flatten()</code> </li>
</ul>
<p>These legacy approaches have several drawbacks:</p>
<ul>
  <li> <strong>Less readable</strong>: The intent to flatten an array is not immediately clear </li>
  <li> <strong>More verbose</strong>: They require more code to achieve the same result </li>
  <li> <strong>Inconsistent</strong>: Different patterns are used across codebases </li>
  <li> <strong>Performance</strong>: Some patterns may be less efficient than the native method </li>
</ul>
<p>The native <code>Array#flat()</code> method clearly expresses the intent to flatten an array and is the modern standard approach.</p>
<h3>What is the potential impact?</h3>
<p>Using legacy flattening techniques makes code harder to read and maintain. The intent to flatten an array is not immediately obvious, which can
slow down code reviews and debugging. Additionally, some legacy patterns may have performance implications compared to the optimized native
method.</p>
<h3>How to fix?</h3>
<p>Replace <code>flatMap()</code> with identity function with <code>flat()</code>.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
const flattened = array.flatMap(x =&gt; x); // Noncompliant
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
const flattened = array.flat();
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-array-flat.md">prefer-array-flat</a> </li>
  <li> MDN - Array.prototype.flat() - <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat">Official
  documentation for the Array.flat() method</a> </li>
  <li> ESLint Unicorn - prefer-array-flat - <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-flat.md">Original ESLint rule documentation</a> </li>
</ul>
<h3>Standards</h3>
<ul>
  <li> ECMAScript 2019 (ES10) - <a href="https://262.ecma-international.org/10.0/#sec-array.prototype.flat">ECMAScript specification for
  Array.prototype.flat</a> </li>
</ul>
<h3>Related Rules</h3>
<ul>
  <li> RSPEC-XXXX - <a href="https://rules.sonarsource.com/javascript/RSPEC-XXXX">Prefer Array.flatMap() over legacy techniques</a> </li>
</ul>
